﻿// -----------------------------------------------------------------------
// <copyright file="Random_Generate.cs" company="FCIS">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace IP_Package.Global_applications
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using IP_Package.Operations;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Random_Generate
    {
        /// <summary>
        /// array of position in image to choose random
        /// </summary>
        private IP_Package.Operations.Restoration.Add_noise.Position[] randArray;

        /// <summary>
        /// number of random takes
        /// </summary>
        private int countOfRandomTakes;

        /// <summary>
        /// image width
        /// </summary>
        private int weidth;

        /// <summary>
        /// image height
        /// </summary>
        private int heigth;

        /// <summary>
        /// Initializes a new instance of the <see cref="Random_Generate"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="heigth">The heigth.</param>
        public Random_Generate(int width, int heigth)
        {
            this.countOfRandomTakes = 0;
            this.weidth = width;
            this.heigth = heigth;
            this.randArray = new Operations.Restoration.Add_noise.Position[width * heigth];
            int i = 0;
            for (int j = 0; j < width; j++)
            {
                for (int k = 0; k < heigth; k++)
                {
                    this.randArray[i].X = j;
                    this.randArray[i].Y = k;
                    i++;
                }
            }
        }

        /// <summary>
        /// Gets or sets the rand array.
        /// </summary>
        /// <value>
        /// The rand array.
        /// </value>
        public IP_Package.Operations.Restoration.Add_noise.Position[] RandArray
        {
            get { return this.randArray; }
            set { this.randArray = value; }
        }

        /// <summary>
        /// Nexts the perfect random.
        /// </summary>
        /// <param name="newRand">The new rand.</param>
        /// <returns>random position</returns>
        public Operations.Restoration.Add_noise.Position NextPerfectRandom(Random newRand)
        {
            int index = newRand.Next((this.weidth * this.heigth) - 1 - this.countOfRandomTakes);
            Operations.Restoration.Add_noise.Position point;
            point.X = this.randArray[index].X;
            point.Y = this.randArray[index].Y;
            this.randArray[index] = this.randArray[(this.weidth * this.heigth) - 1 - this.countOfRandomTakes];
            this.countOfRandomTakes++;
            return point;
        }
    }
}
